<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>
<body>
	<script>
		var phone = '18988892311'
		// 查找并替换
		// console.log(phone.replace('888','***'))
		// 查找开头的3个数字
		// console.log(phone.replace(/^\d{3}/,'***'))
		// 查找结尾的4个数字
		// console.log(phone.replace(/\d{4}$/,'****'))
		// 查找中间的4个位数字
		// console.log(phone.replace(/(\d{3})\d{4}(\d{4})/,'$1****$2'))
		// 替换身份证中的生日部分为*******
		var id = '110332199803220780'
		console.log(id.replace(/(\d{6})\d{8}(\d{4})/,'$1********$2'))
	</script>
</body>
</html>